<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert title here</title>
<link href="/resource/css/bootstrap.css" rel="stylesheet">
<script type="text/javascript" src="/resource/js/jquery-3.2.1.js"></script>
<script type="text/javascript" src="/resource/js/bootstrap.js"></script>
<head>
<meta charset="UTF-8">
<title>spu列表页面</title>
</head>
<body>

	<div>
		<form id="likeForm">
			<div class="container">
				<div class="row">
					<div class="col-md-2.5">
						<div class="form-group mx-sm-3 mb-2">
							<label for="inputPassword2" class="sr-only">Password</label> <input
								type="text" class="form-control" id="inputPassword2"
								name="goodsName" placeholder="名称" value="${vo.goodsName }">
						</div>
					</div>

					<div class="col-md-2.5">
						<div class="form-group mx-sm-3 mb-2">
							<label for="inputPassword2" class="sr-only">Password</label> <input
								type="text" class="form-control" id="inputPassword2"
								name="caption" placeholder="标题" value="${vo.caption }">
						</div>
					</div>
					<div class="col-md-2">
						<div>
							品牌 <select name="brandId">
								<option value="0">请选择</option>
								<c:forEach items="${brands }" var="b">
									<option value="${b.id }" ${vo.brandId==b.id?"selected":"" }>${b.name }</option>

								</c:forEach>
							</select>
						</div>

					</div>
					<div class="col-md-2">
						排序数据项 <select name="orderField">
							<option value="goods_name"
								${vo.orderField=="goods_name"?"selected":"" }>名称</option>
							<option value="caption"
								${vo.orderField=="caption"?"selected":"" }>标题</option>
							<option value="category_id"
								${vo.orderField=="category_id"?"selected":"" }>品牌</option>
							<option value="brand_id"
								${vo.orderField=="brand_id"?"selected":"" }>分类</option>
							<option value="is_marketable"
								${vo.orderField=="is_marketable"?"selected":"" }>是否上架</option>

						</select>
					</div>
					<div class="col-md-2">
						排序方式 <select name="orderType">
							<option value="asc" ${vo.orderType=='asc'?"selected":"" }>升序</option>
							<option value="desc" ${vo.orderType=='desc'?"selected":"" }>降序</option>
						</select>
					</div>

				</div>

			</div>
		</form>
		<button type="button" onclick="likeFind()">查询</button>

	</div>
	<div>
	<button type="button" onclick="dels()">批量删除</button>
	<button type="button" onclick="add()">添加</button>
	
	</div>
	<table class="table table-hover">
		<tr>
			<td>id</td>
			<td>名称</td>
			<td>图片</td>
			<td>品牌</td>
			<td>分类</td>
			<td>上架</td>
			<td>标题</td>

			<td>操作</td>
		</tr>
		<c:forEach items="${list }" var="s">
			<tr>
				<td>
				<input type="checkbox" name="ck" value="${s.id }">
				${s.id }</td>
				<td>${s.goodsName }</td>
				<td><img alt="" src="/pic/${s.smallPic }" width="50"
					height="50"></td>
				<td>${s.brand.name }</td>
				<td>${s.category.name }</td>
				<td>${s.isMarketable==1?"上架":"不上架" }</td>
				<td>${s.caption }</td>
				<td>
				<button type="button" onclick="update(${s.id })">修改</button>
				|
				<button type="button" onclick="del(${s.id })">删除</button>|
				<button type="button" onclick="addsku(${s.id })">添加sku</button>
				</td>
			</tr>

		</c:forEach>
	</table>
	<jsp:include page="/WEB-INF/view/common/pages.jsp"></jsp:include>
	<script type="text/javascript">
		function goPage(pageNum) {
			var url = "spu/list?pageNum=" + pageNum;
			$("#workArea").load(url, $("#likeForm").serialize());
		}
		function likeFind() {
			var url = "spu/list";
			$("#workArea").load(url, $("#likeForm").serialize());
		}
		function dels(){
			var ids=new Array();
			$("[name='ck']:checked").each(function(i){
				ids[i]=$(this).val();
			})
			if(ids.length==0){
				alert("请至少选择一条数据")
				return;
			}
			alert(ids)
			var reg=confirm("确定要删除吗");
			if(reg){
				$.post("spu/dels",{ids:ids},function(flag){
					if(flag){
						alert("success");
						url="spu/list";
						$("#workArea").load(url);
					}else{
						alert("fail");
					}
				})
			}
		}
		function del(id){
			if(confirm("确定要删除吗")){
				$.post("spu/del",{id:id},function(flag){
					if(flag){
						alert("success");
						url="spu/list";
						$("#workArea").load(url);
					}else{
						alert("fail");
					}
				})
			}
		}
		function add(){
			url="spu/add";
			$("#workArea").load(url);
		}
		function update(id){
			url="spu/update?id="+id;
			$("#workArea").load(url);
		}
		function addsku(id){
			url="sku/toadd?id="+id;
			$("#workArea").load(url);
		}
	</script>
</body>
</html>